﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CodeStudy.WPF.Model;

namespace CodeStudy.WPF
{
    /// <summary>
    /// Interaction logic for ChartTest.xaml
    /// </summary>
    public partial class ChartTest : PageControlBase
    {
        public ChartTest()
        {
            InitializeComponent();

            this.chtTest.BeginUpdate();

            List<PopulationStatistics> source = this.CreateFakeData();
            PopulationChartDataProvider dataProvider = new PopulationChartDataProvider(source);

            this.chtTest.DataContext = dataProvider;
            //this.chtTest.Data.ItemsSource = dataProvider.Data;
            //this.chtTest.Data.ItemNames = dataProvider.ItemNames;
            //this.chtTest.Data.Children[0].Values = dataProvider.PopulationSeries;

            chtTest.View.AxisY.Min = 500;
            chtTest.View.AxisY.Max = 4000;

            this.chtTest.EndUpdate();
        }

        /// <summary>
        /// Creates the fake data for the chart
        /// </summary>
        /// <returns></returns>
        private List<PopulationStatistics> CreateFakeData()
        {
            List<PopulationStatistics> fakeData = new List<PopulationStatistics>();

            fakeData.Add(new PopulationStatistics() { Population = 1000, UnitName = "BeiJing" });
            fakeData.Add(new PopulationStatistics() { Population = 3000, UnitName = "HeNan" });
            fakeData.Add(new PopulationStatistics() { Population = 2700, UnitName = "ShanDong" });
            fakeData.Add(new PopulationStatistics() { Population = 900, UnitName = "TianJin" });

            return fakeData;
        }

        private void DataSeries_Loaded(object sender, RoutedEventArgs e)
        {
            string s = sender.ToString();
        }

        private void Label_Loaded(object sender, RoutedEventArgs e)
        {
            string s = sender.ToString();
        }
    }
}
